#include "locations/classroom.hh"
#include "characters/enemies/StudentEnemy.hh"
#include "locations/location.hh"
#include "items/item.hh"

#include <string>
#include <iostream>
#include <random>

Classroom::Classroom() {}

std::string Classroom::getName() const
{
    return "Abandoned Classroom";
}

std::string Classroom::getDescription() const
{
    return "A place filled with an old atmosphere, where various items can be found.";
}

std::string Classroom::when_enter()
{
    return "You entered the abandoned classroom.";
}

Player &Classroom::in(Player &a)
{
    if (this->have_serached)
    {
        std::cout << "You've already been to this classroom and can't find any new items." << std::endl;
    }
    else
    {
        Item *new_item = Classroom::search();
        a.addToInventory(new_item);
        if (new_item->getName() == "Snack")
        {
            a.item_number[4] += rand() % 3 + 1;
            std::cout << "You have found " << new_item->getName() << "! Number:[" << a.item_number[4] << "]" << std::endl;
        }
        else if (new_item->getName() == "Heavy Textbook")
        {
            a.item_number[3] += rand() % 3 + 1;
            a.setDefensePower(a.getDefensePower() + 80);
            std::cout << "You have found " << new_item->getName() << "! Number:[" << a.item_number[3] << "]" << std::endl;
        }
        else if (new_item->getName() == "Chalk")
        {
            a.item_number[2] += rand() % 6 + 1;
            std::cout << "You have found " << new_item->getName() << "! Number:[" << a.item_number[2] << "]" << std::endl;
        }
        else
        {
            a.item_number[1]++;
        }
    }
    return a;
}

std::string Classroom::when_exit() const
{
    return "You exited the abandoned classroom.";
}

Item *Classroom::search()
{
    int a = rand() % 5;
    Item *new_item = new Item("Chalk", "A piece of chalk. It can attack enemies.", "Tool", 60, 0, 0, 0, true, false);
    if (a == 1)
    {
        new_item = new Item("Snack", "Restores energy but lowers guard.", "Snack", 0, 0, 200, -50, true, false);
    }
    else if (a == 2)
    {
        new_item = new Item("Heavy Textbook", "A large and heavy textbook. Provides a strong defense boost.", "Book", 0, 80, 0, 0, false, true);
    }
    else if (a == 3)
    {
        new_item = new Item("Blackboard Eraser", "A useful tool to erase things from the blackboard.", "Tool", 150, 0, 0, 0, true, false);
    }
    std::cout << "You searched the classroom and found " << new_item->getName() << std::endl;
    return new_item;
}